package servlet;

import service.DepartmentService;
import service.DepartmentServiceImpl;
import utils.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 陈金平
 * @Description
 * @create 2020/11/22 18:57
 */
public class DelAllDepartments extends HttpServlet {
    private DepartmentService departmentService = new DepartmentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");

        String[] dIds = req.getParameterValues("did");

        List<Integer> list = new ArrayList<>();
        for (String dId : dIds) {
            list.add(Integer.parseInt(dId));
        }

        departmentService.delAllDepartments(list);
        resp.sendRedirect("/all_departments");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
